package com.loong.ems.controller;

import com.github.pagehelper.PageInfo;
import com.loong.ems.domain.entity.EmpPostLevel;
import com.loong.ems.domain.vo.resp.Result;
import com.loong.ems.service.EmpPostLevelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 龙勇-229970722
 * @date 2025-01-02 10:22
 * @description: 岗位岗级管理
 */
@RestController
@RequestMapping("/level")
@Log4j2
@CrossOrigin
@Tag(name = "岗位岗级管理 API" , description = "岗位岗级管理 API")
public class EmpPostLevelController {

    @Autowired
    private EmpPostLevelService empPostLevelService;

    /**
     * 获取岗位岗级列表
     * @return
     */
    @Operation(summary = "获取岗位岗级列表")
    @GetMapping("/list")
    public Result<List<EmpPostLevel>> list() {
        return Result.success(empPostLevelService.list());
    }

    /**
     * 分页获取岗位列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Operation(summary = "分页获取岗位列表")
    @GetMapping("/listByPage")
    public Result<PageInfo<EmpPostLevel>> listByPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        PageInfo<EmpPostLevel> pageInfo = empPostLevelService.listByPage(pageNum, pageSize);
        return Result.success(pageInfo);
    }

    /**
     * 新增岗位岗级
     * @param empPostLevel
     * @return
     */
    @Operation(summary = "新增岗位岗级")
    @PostMapping("/add")
    public Result<String> add(@RequestBody EmpPostLevel empPostLevel) {
        empPostLevelService.add(empPostLevel);
        return Result.success("新增岗位岗级成功");
    }

    /**
     * 修改岗位岗级
     * @param empPostLevel
     * @return
     */
    @Operation(summary = "修改岗位岗级")
    @PostMapping("/update")
    public Result<String> update(@RequestBody EmpPostLevel empPostLevel) {
        empPostLevelService.update(empPostLevel);
        return Result.success("修改岗位岗级成功");
    }

    /**
     * 删除岗位岗级
     * @param id
     * @return
     */
    @Operation(summary = "删除岗位岗级")
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteById(@PathVariable("id") Long id) {
        empPostLevelService.deleteById(id);
        return Result.success("删除岗位岗级成功");
    }

    /**
     * 查看废弃的岗位岗级表
     * @return
     */
    @Operation(summary = "查看废弃的岗位岗级表")
    @GetMapping("/listDelete")
    public Result<List<EmpPostLevel>> listDelete() {
        return Result.success(empPostLevelService.listDelete());
    }

    /**
     * 恢复岗位岗级
     * @param id
     * @return
     */
    @Operation(summary = "恢复岗位岗级")
    @PostMapping("/recover/{id}")
    public Result<String> recover(@PathVariable("id") Long id) {
        empPostLevelService.recover(id);
        return Result.success("恢复岗位岗级成功");
    }

    /**
     * 获取所有岗位岗级包括已删除的
     * @return
     */
    @Operation(summary = "获取所有岗位岗级包括已删除的")
    @GetMapping("/getAll")
    public Result<List<EmpPostLevel>> getAll() {
        return Result.success(empPostLevelService.getAll());
    }

    /**
     * 分页模糊查询岗位岗级
     * @param name 岗位名称
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return
     */
    @Operation(summary = "分页模糊查询岗位岗级")
    @GetMapping("/search")
    public Result<PageInfo<EmpPostLevel>> search(
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize)
    {
        List<EmpPostLevel> empPostLevels = empPostLevelService.search(name, pageNum, pageSize);
        return Result.success(new PageInfo<>(empPostLevels));
    }

}
